package com.wolf.controller;

import com.wolf.pojo.Wl_sys_dictionary;
import com.wolf.service.Wl_sys_dictionaryService;
import com.wolf.util.Math;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
@ComponentScan
public class Wl_sys_dictionaryController {

    @Autowired
    private Wl_sys_dictionaryService wl_sys_dictionaryService;

    public void setWl_sys_dictionaryService(Wl_sys_dictionaryService wl_sys_dictionaryService) {
        this.wl_sys_dictionaryService = wl_sys_dictionaryService;
    }

    /**
     * 查询所有
     * @param modelMap
     * @return
     */
    @RequestMapping("wl_sys_dictionary_getall")
    public String getAll(ModelMap modelMap){

        List<Wl_sys_dictionary> list = wl_sys_dictionaryService.getAll();

        modelMap.addAttribute("wl_sys_dictionary_list",list);

        return "table_wl_sys_dictionary";
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @RequestMapping("wl_sys_dictionary_delete")
    public String wl_sys_dictionary_delete(String id){

        wl_sys_dictionaryService.deleteByPrimaryKey(id);

        return "redirect:wl_sys_dictionary_getall";
    }

    /**
     * 查询单个对象
     * @param id
     * @return
     */
    @RequestMapping("wl_sys_dictionary_getbyid")
    @ResponseBody
    public Wl_sys_dictionary wl_sys_dictionary_getbyid(String id){

        return wl_sys_dictionaryService.selectByPrimaryKey(id);
    }

    /**
     * 修改
     * @param id
     * @param categoryname
     * @param categorycode
     * @param categorydesc
     * @param keyname
     * @param keycode
     * @param keydesc
     * @return
     */
    @RequestMapping("wl_sys_dictionary_update")
    @ResponseBody
    public int wl_sys_dictionary_update(String id,String categoryname,String categorycode,
                                           String categorydesc,String keyname,String keycode,String keydesc){

        Wl_sys_dictionary wl_sys_dictionary = new Wl_sys_dictionary();
        wl_sys_dictionary.setId(id);
        wl_sys_dictionary.setCategoryname(categoryname);
        wl_sys_dictionary.setCategorycode(categorycode);
        wl_sys_dictionary.setCategorydesc(categorydesc);
        wl_sys_dictionary.setKeyname(keyname);
        wl_sys_dictionary.setKeycode(keycode);
        wl_sys_dictionary.setKeydesc(keydesc);
        wl_sys_dictionary.setUpdatedatetime(new Date());

        return wl_sys_dictionaryService.updateByPrimaryKeySelective(wl_sys_dictionary);
    }

    /**
     * 新增
     * @param categoryname
     * @param categorycode
     * @param categorydesc
     * @param keyname
     * @param keycode
     * @param keydesc
     * @return
     */
    @RequestMapping("wl_sys_dictionary_insert")
    @ResponseBody
    public int wl_sys_dictionary_insert(String categoryname,String categorycode,
                                        String categorydesc,String keyname,String keycode,String keydesc){

        Wl_sys_dictionary wl_sys_dictionary = new Wl_sys_dictionary();
        wl_sys_dictionary.setId(Math.random());
        wl_sys_dictionary.setCategoryname(categoryname);
        wl_sys_dictionary.setCategorycode(categorycode);
        wl_sys_dictionary.setCategorydesc(categorydesc);
        wl_sys_dictionary.setKeyname(keyname);
        wl_sys_dictionary.setKeycode(keycode);
        wl_sys_dictionary.setKeydesc(keydesc);
        wl_sys_dictionary.setCreatedatetime(new Date());

        return wl_sys_dictionaryService.insertSelective(wl_sys_dictionary);
    }

    /**
     * 模糊查询
     * @param modelMap
     * @param categoryname
     * @param keyname
     * @return
     */
    @RequestMapping("wl_sys_dictionary_getselecttive")
    public String getSelective(ModelMap modelMap,String categoryname,String keyname){

        List<Wl_sys_dictionary> list = wl_sys_dictionaryService.getSelective(categoryname,keyname);

        modelMap.addAttribute("wl_sys_dictionary_list",list);

        return "table_wl_sys_dictionary";
    }
}
